using System;
using System.Text.RegularExpressions;
using System.Web.UI.WebControls;

namespace Adge.UI.WebControls
{
	/// <summary>
	/// Summary description for DGHelpers.
	/// </summary>
	public class DGHelpers
	{
		public static void UpdateColumnHeaders(DataGrid dg, string sortExpression, bool sortAscending)
		{
			foreach(DataGridColumn c in dg.Columns)
			{
				c.HeaderText = Regex.Replace(c.HeaderText, "&nbsp;<.*>", String.Empty);  // Clear any <img> tags that might be present

				if (sortExpression != string.Empty && c.SortExpression == sortExpression)
				{
					if (sortAscending)
						c.HeaderText += string.Concat("&nbsp;<img src=\"", dg.ResolveUrl("~/images/up.gif"), "\" border=\"0\" width=\"11\" height=\"7\" />");
					else
						c.HeaderText += string.Concat("&nbsp;<img src=\"", dg.ResolveUrl("~/images/down.gif"), "\" border=\"0\" width=\"11\" height=\"7\" />");
				}
			}
		}

		public static void ResetDataGrid(DataGrid dg)
		{
			dg.CurrentPageIndex = 0;
			dg.EditItemIndex = -1;
		}

		public static string DisplayDepth(int depth)
		{
			// TODO: Use styles here, rather than &nbsp;'s
			string output = string.Empty;

			for (int i = 1; i < depth; i++)
				output += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

			return output;
		}
	}
}
